package com.turing.post.account.util;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

import com.turing.post.util.PCPSUtil;

/**
 * 子帐户明细
 * @author kz
 * @date 2012-12-17
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "SubAccountDetail")
@IdClass(SubAccountDetail.class)
public class SubAccountDetail implements Serializable {
	
	public SubAccountDetail(){
		super();
	}
	/**
	 * 子帐号
	 */
	private BigInteger subAccNo;
	/**
	 * 帐务日期
	 */
	private Date tranDate;
	/**
	 * 交易时间
	 */
	private Date tranTime;
	/**
	 * 帐户子系统流水号
	 */
	private String accSeqNo;
	/**
	 * 记帐序号
	 */
	private Integer accSubSeqNo;
	/**
	 * 贷方发生额
	 */
	private BigInteger creditAmount = BigInteger.ZERO;
	/**
	 * 借方发生额
	 */
	private BigInteger debitAmount = BigInteger.ZERO;
	/**
	 * 交易后余额
	 */
	private BigInteger balance;
	/**
	 *交易摘要 
	 */
	private String summary;
	
	@Column(name = "SUBACCNO", nullable = false)
	public BigInteger getSubAccNo() {
		return subAccNo;
	}
	public void setSubAccNo(BigInteger subAccNo) {
		this.subAccNo = subAccNo;
	}
	
	@Column(name = "TRANDATE", nullable = false)
	public Date getTranDate() {
		return tranDate;
	}
	public void setTranDate(Date tranDate) {
		this.tranDate = tranDate;
	}
	
	@Column(name = "TRANTIME", nullable = false)
	public Date getTranTime() {
		return tranTime;
	}
	public void setTranTime(Date tranTime) {
		this.tranTime = tranTime;
	}
	
	@Id
	@Column(name = "ACCSEQNO", nullable = false)
	public String getAccSeqNo() {
		return accSeqNo;
	}
	public void setAccSeqNo(String accSeqNo) {
		this.accSeqNo = accSeqNo;
	}
	
	@Id
	@Column(name = "ACCSUBSEQNO", nullable = false)
	public Integer getAccSubSeqNo() {
		return accSubSeqNo;
	}
	public void setAccSubSeqNo(Integer accSubSeqNo) {
		this.accSubSeqNo = accSubSeqNo;
	}
	
	@Column(name = "CREDITAMOUNT", nullable = false)
	public BigInteger getCreditAmount() {
		return creditAmount;
	}
	public void setCreditAmount(BigInteger creditAmount) {
		this.creditAmount = creditAmount;
	}

	@Column(name = "DEBITAMOUNT", nullable = false)
	public BigInteger getDebitAmount() {
		return debitAmount;
	}
	public void setDebitAmount(BigInteger debitAmount) {
		this.debitAmount = debitAmount;
	}

	@Column(name = "BALANCE", nullable = false)
	public BigInteger getBalance() {
		return balance;
	}
	public void setBalance(BigInteger balance) {
		this.balance = balance;
	}
	
	@Column(name = "SUMMARY", nullable = false)
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;

		result = prime * result
				+ ((this.getAccSeqNo() == null) ? 0 : this.getAccSeqNo().hashCode());
		result = prime * result
				+ ((this.getAccSubSeqNo() == null) ? 0 : this.getAccSubSeqNo().hashCode());

		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof SubAccountDetail))
			return false;
	
		SubAccountDetail other = (SubAccountDetail) obj;
		
		if ( !PCPSUtil.compareObject(this.getAccSeqNo(), other.getAccSeqNo()))
			return false;

		return PCPSUtil.compareObject(this.getAccSubSeqNo(), other.getAccSubSeqNo());
	}	
}
